package com.justcan.demo.cartoon.utils.anim.touch;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;

import com.justcan.demo.cartoon.utils.anim.AnimObject;
import com.justcan.demo.cartoon.utils.anim.AnimObjectGroup;


public class TouchAnimObjectGroup extends AnimObjectGroup implements IAnimTouchable {

	public TouchAnimObjectGroup(View mRootAnimView, Context mContext) {
		super(mRootAnimView, mContext);
	}

	/**
	 * 分发成功的TouchAnimObject
	 */
	private TouchAnimObject mTargetAnimObject = null;

	/**
	 * 点击事件
	 */
	@Override
	public boolean onTouch(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN || mTargetAnimObject == null) {
			for (int i = 0; i < mAnimObjects.size(); i++) {
				AnimObject object = mAnimObjects.get(i);
				if (object instanceof TouchAnimObject) {
					if (((TouchAnimObject) object).onTouch(event)) {
						// 接受事件
						mTargetAnimObject = (TouchAnimObject) object;
						return true;
					}
				}
			}
		} else if (mTargetAnimObject != null) {
			return mTargetAnimObject.onTouch(event);
		}
		return false;
	}
}
